from django.db.models import Q
from django.shortcuts import get_object_or_404

from my_example.models import renwu_jieng, renwu, jineng_key_value, jineng_attrs, renwu_zhuangbei, zhuangbei_key_value, \
    zhuangbei, chenghao_key_value, renwuattrs


# ===============基础属性篇
def zhili_result(ren):
    # 计算总智力

    # 计算技能智力加成
    jn_attrs = get_jineng_attrs_for_name(ren, "智力")
    jn_zl = sum_attrs(jn_attrs)

    # 获取人物本身的智力
    # print(ren.get_nums_type_display())
    if ren.get_nums_type_display() == "智力":
        rw_zl = ren.nums
        rw_zl2 = ren.nums_bf
    else:
        rw_zl, rw_zl2 = 0, 0
    # 获取装备智力
    zb_attrs = get_zhuangbei_attrs_for_name(ren, '智力')
    zb_zl = sum_attrs(zb_attrs)

    # 获取装备智力增幅
    zb_zf_attrs = get_zhuangbei_attrs_for_name(ren, "智力增幅")
    zb_zf = sum_attrs(zb_zf_attrs)

    # 获取称号智力
    ch_zj=get_chenghao_attr_for_name(ren,"智力")
    # 获取称号智力增幅
    ch_zf=get_chenghao_attr_for_name(ren,"智力增幅")
    # print(zb_zf)
    # 计算结果
    result = (jn_zl + rw_zl+ch_zj) * (1 + zb_zf+ch_zf) + rw_zl2 + zb_zl

    try:
        renattr=renwuattrs.objects.get(renwu=ren)
        renattr.zhili=round(result)
        renattr.save()
    except Exception as e:
        print(e)
        renwuattrs(renwu=ren,zhili=round(result)).save()

    # return round(result)


def ganzhi_result(ren):
    '''
    计算人物总感知
    :param pk:
    :return:
    '''

    # 计算技能加成
    jn_jc = sum_attrs(get_jineng_attrs_for_name(ren, "感知"))

    # 计算技能增幅
    jn_zf = sum_attrs(get_jineng_attrs_for_name(ren, "感知增幅"))


    # 获取人物本身属性
    if ren.get_nums_type_display() == "感知":
        rw = ren.nums
        rw2 = ren.nums_bf
    else:
        rw, rw2 = 0, 0


    # 获取装备加成
    zb_jc = sum_attrs(get_zhuangbei_attrs_for_name(ren, '感知'))

    # 获取装备增幅
    zb_zf = sum_attrs(get_zhuangbei_attrs_for_name(ren, "感知增幅"))

    # 获取称号增加
    ch_zj=get_chenghao_attr_for_name(ren,"感知")
    # 获取称号增幅
    ch_zf=get_chenghao_attr_for_name(ren,"感知增幅")

    # 计算结果
    result = (jn_jc + rw+ch_zj) * (1 + jn_zf + zb_zf+ch_zf) + rw2 + zb_jc

    try:
        renattr=renwuattrs.objects.get(renwu=ren)
        renattr.ganzhi=result
        renattr.save()
    except Exception as e:
        print(e)
        renwuattrs(renwu=ren,ganzhi=result).save()

    # return round(result)


def liliang_result(ren):
    '''
    计算人物总力量
    :param pk:
    :return:
    '''

    # 计算技能加成
    jn_jc = sum_attrs(get_jineng_attrs_for_name(ren, "力量"))

    # 计算技能增幅
    jn_zf = sum_attrs(get_jineng_attrs_for_name(ren, "力量增幅"))
    # 获取人物本身属性
    if ren.get_nums_type_display() == "力量":
        rw = ren.nums
        rw2 = ren.nums_bf
    else:
        rw, rw2 = 0, 0
    # 获取装备加成
    zb_jc = sum_attrs(get_zhuangbei_attrs_for_name(ren, '力量'))

    # 获取装备增幅
    zb_zf = sum_attrs(get_zhuangbei_attrs_for_name(ren, "力量增幅"))

    # 获取称号增加
    ch_zj=get_chenghao_attr_for_name(ren,"力量")
    # 获取称号增幅
    ch_zf=get_chenghao_attr_for_name(ren,"力量增幅")

    # 计算结果
    result = (jn_jc + rw+ch_zj) * (1 + jn_zf + zb_zf+ch_zf) + rw2 + zb_jc

    try:
        renattr=renwuattrs.objects.get(renwu=ren)
        renattr.liliang=result
        renattr.save()
    except Exception as e:
        print(e)
        renwuattrs(renwu=ren,liliang=result).save()
    # return round(result)


def minjie_result(ren):
    '''
    计算人物总敏捷
    :param pk:
    :return:
    '''

    # 计算技能加成
    jn_jc = sum_attrs(get_jineng_attrs_for_name(ren, "敏捷"))

    # 计算技能增幅
    jn_zf = sum_attrs(get_jineng_attrs_for_name(ren, "敏捷增幅"))
    # 获取人物本身属性
    if ren.get_nums_type_display() == "敏捷":
        rw = ren.nums
        rw2 = ren.nums_bf
    else:
        rw, rw2 = 0, 0
    # 获取装备加成
    zb_jc = sum_attrs(get_zhuangbei_attrs_for_name(ren, '敏捷'))

    # 获取装备增幅
    zb_zf = sum_attrs(get_zhuangbei_attrs_for_name(ren, "敏捷增幅"))

    # 获取称号增加
    ch_zj=get_chenghao_attr_for_name(ren,"敏捷")
    # 获取称号增幅
    ch_zf=get_chenghao_attr_for_name(ren,"敏捷增幅")

    # 计算结果
    result = (jn_jc + rw+ch_zj) * (1 + jn_zf + zb_zf+ch_zf) + rw2 + zb_jc

    try:
        renattr=renwuattrs.objects.get(renwu=ren)
        renattr.minjie=result
        renattr.save()
    except Exception as e:
        print(e)
        renwuattrs(renwu=ren,minjie=result).save()

    # return round(result)


# ================魔法篇

def moming_result(ren):
    # 计算总魔命

    # 1. 计算技能魔命加成
    jn_attrs = get_jineng_attrs_for_name(ren, "魔法命中")
    jn_mm = sum_attrs(jn_attrs)

    # 2. 计算装备魔命加成
    zb_attrs = get_zhuangbei_attrs_for_name(ren, "魔法命中")
    zb_mm = sum_attrs(zb_attrs)

    # 3. 计算技能魔命增幅
    jn_zf_attrs = get_jineng_attrs_for_name(ren, '魔法命中增幅')
    jn_zf_mm = sum_attrs(jn_zf_attrs)

    # 4. 计算装备魔命增幅
    zb_zf_attrs = get_zhuangbei_attrs_for_name(ren, '魔法命中增幅')
    zb_zf_mm = sum_attrs(zb_zf_attrs)

    # 5. 计算结果
    result = (jn_mm + zb_mm + 100) * (1 + jn_zf_mm + zb_zf_mm)
    return int(result)


def mogong_result(ren):
    # 计算总魔攻

    # 1. 计算技能魔攻加成
    jn_attrs = get_jineng_attrs_for_name(ren, "魔法攻击力")
    jn_jc = sum_attrs(jn_attrs)
    # print("技能魔攻加成", jn_jc)

    # 2. 计算装备魔攻加成
    zb_attrs = get_zhuangbei_attrs_for_name(ren, "魔法攻击力")
    zb_jc = sum_attrs(zb_attrs)
    # print("装备魔攻加成", zb_jc)

    # 3. 计算技能魔攻增幅
    jn_zf_attrs = get_jineng_attrs_for_name(ren, '魔法攻击力增幅')
    jn_zf = sum_attrs(jn_zf_attrs)
    # print("技能魔攻增幅", jn_zf)
    # 4. 计算装备魔攻击增幅
    zb_zf_attrs = get_zhuangbei_attrs_for_name(ren, '魔法攻击力增幅')
    zb_zf = sum_attrs(zb_zf_attrs)
    # print("装备魔攻增幅", zb_zf)

    # 5.获取魔命
    mm = moming_result(ren)
    # print("魔法命中:", mm)
    # 6.计算智力和感知加成的魔攻
    renattr=renwuattrs.objects.get(renwu=ren)
    m = renattr.zhili * 3 + renattr.ganzhi * 2
    # print("属性基础魔攻:", m)

    # 6. 计算结果
    # [ ( 智力*3+感知*2)*(1+(魔法命中-100)/1000 ) + 装备技能增加的魔攻]*(1+装备技能魔攻增幅)
    result = (int(m * (1 + (mm - 100) / 1000)) + jn_jc + zb_jc) * (1 + jn_zf + zb_zf)
    return int(result)


def mochuan_result(ren):
    '''
    计算人物魔法穿透
    :param pk:
    :return:
    '''

    # 1. 获取技能魔穿
    jn_mc = sum_attrs(get_jineng_attrs_for_name(ren, "魔法穿透"))

    # 2. 获取装备魔穿
    zb_mc = sum_attrs(get_zhuangbei_attrs_for_name(ren, '魔法穿透'))

    # 3. 获取技能魔穿增幅
    jn_zf_mc = sum_attrs(get_jineng_attrs_for_name(ren, '魔法穿透增幅'))

    # 4. 获取装备魔穿增幅
    zb_zf_mc = sum_attrs(get_zhuangbei_attrs_for_name(ren, '魔法穿透增幅'))

    # 5. 计算智力和感知魔穿加成
    renattr = renwuattrs.objects.get(renwu=ren)
    m = renattr.zhili * 2 + renattr.ganzhi

    # 6. 计算结果
    result = (m + jn_mc + zb_mc) * (1 + jn_zf_mc + zb_zf_mc)

    return round(result)


def pojia_result(ren):
    # 获取人物

    # 1. 获取技能破甲
    jn_mc = sum_attrs(get_jineng_attrs_for_name(ren, "破甲"))

    # 2. 获取装备破甲
    zb_mc = sum_attrs(get_zhuangbei_attrs_for_name(ren, '破甲'))

    # 3. 获取技能破甲增幅
    jn_zf_mc = sum_attrs(get_jineng_attrs_for_name(ren, '破甲增幅'))

    # 4. 获取装备破甲增幅
    zb_zf_mc = sum_attrs(get_zhuangbei_attrs_for_name(ren, '破甲增幅'))

    # 5. 计算力量敏捷破甲加成
    renattr = renwuattrs.objects.get(renwu=ren)
    m = renattr.liliang * 3 + renattr.minjie

    # 6. 计算结果
    result = (m + jn_mc + zb_mc) * (1 + jn_zf_mc + zb_zf_mc)
    return int(result)


def zhiming_result(ren):
    '''
    计算人物致命
    :param pk:
    :return:
    '''

    # 1. 获取技能致命
    jn_mc = sum_attrs(get_jineng_attrs_for_name(ren, "致命"))

    # 2. 获取装备致命
    zb_mc = sum_attrs(get_zhuangbei_attrs_for_name(ren, '致命'))

    # 3. 获取技能致命增幅
    jn_zf = sum_attrs(get_jineng_attrs_for_name(ren, '致命增幅'))

    # 4. 获取装备致命增幅
    zb_zf = sum_attrs(get_zhuangbei_attrs_for_name(ren, '致命增幅'))

    # 5. 计算结果
    result = (jn_mc + zb_mc) * (1 + jn_zf + zb_zf)

    return round(result)


def duoshan_result(ren):
    '''
    计算人物躲闪
    :param pk:
    :return:
    '''

    # 1. 获取技能致命
    jn_mc = sum_attrs(get_jineng_attrs_for_name(ren, "躲闪"))

    # 2. 获取装备致命
    zb_mc = sum_attrs(get_zhuangbei_attrs_for_name(ren, '躲闪'))

    # 3. 获取技能致命增幅
    jn_zf = sum_attrs(get_jineng_attrs_for_name(ren, '躲闪增幅'))

    # 4. 获取装备致命增幅
    zb_zf = sum_attrs(get_zhuangbei_attrs_for_name(ren, '躲闪增幅'))

    # 5. 计算结果

    # 属性点增加的躲闪
    renattr = renwuattrs.objects.get(renwu=ren)
    s = renattr.ganzhi * 0.4 + renattr.minjie * 0.4

    result = (jn_mc + zb_mc + s) * (1 + jn_zf + zb_zf)

    return round(result)

def dongcha_result(ren):
    '''
    计算人物洞察
    :param pk:
    :return:
    '''

    # 1. 获取技能洞察
    jn_mc = sum_attrs(get_jineng_attrs_for_name(ren, "洞察"))

    # 2. 获取装备洞察
    zb_mc = sum_attrs(get_zhuangbei_attrs_for_name(ren, '洞察'))

    # 3. 获取技能洞察增幅
    jn_zf = sum_attrs(get_jineng_attrs_for_name(ren, '洞察增幅'))

    # 4. 获取装备洞察增幅
    zb_zf = sum_attrs(get_zhuangbei_attrs_for_name(ren, '洞察增幅'))

    # 5. 计算结果

    # 属性点增加的洞察
    renattr = renwuattrs.objects.get(renwu=ren)
    s = renattr.ganzhi * 0.2 + renattr.zhili * 0.1

    result = (jn_mc + zb_mc + s) * (1 + jn_zf + zb_zf)
    return round(result)

def chushou_result(ren):
    '''
    计算人物出手
    :param pk:
    :return:
    '''

    # 1. 获取技能出手
    jn_mc = sum_attrs(get_jineng_attrs_for_name(ren, "出手速度"))

    # 2. 获取装备出手
    zb_mc = sum_attrs(get_zhuangbei_attrs_for_name(ren, '出手速度'))

    # 3. 获取技能出手增幅
    jn_zf = sum_attrs(get_jineng_attrs_for_name(ren, '出手增幅'))

    # 4. 获取装备出手增幅
    zb_zf = sum_attrs(get_zhuangbei_attrs_for_name(ren, '出手增幅'))

    # 5. 计算结果

    # 属性点增加的出手
    renattr = renwuattrs.objects.get(renwu=ren)
    s = renattr.minjie * 3+ renattr.ganzhi* 1.5

    result = (jn_mc + zb_mc + s) * (1 + jn_zf + zb_zf)

    return round(result)

def wushimofan_result(ren):
    '''
    计算人物无视魔法反馈
    :param pk:
    :return:
    '''

    # 1. 获取技能无视
    jn_mc = sum_attrs(get_jineng_attrs_for_name(ren, "无视魔法反馈"))

    # 2. 获取装备无视
    zb_mc = sum_attrs(get_zhuangbei_attrs_for_name(ren, '无视魔法反馈'))



    # 3. 计算结果

    result = (jn_mc + zb_mc )

    return round(result)
# ============物理篇


def mingzhong_result(ren):
    # 计算总命中

    # 1. 计算技能命中加成
    jn_attrs = get_jineng_attrs_for_name(ren, "命中")
    jn_mm = sum_attrs(jn_attrs)

    # 2. 计算装备命中加成
    zb_attrs = get_zhuangbei_attrs_for_name(ren, "命中")
    zb_mm = sum_attrs(zb_attrs)

    # 3. 计算技能命中增幅
    jn_zf_attrs = get_jineng_attrs_for_name(ren, '命中增幅')
    jn_zf_mm = sum_attrs(jn_zf_attrs)

    # 4. 计算装备命中增幅
    zb_zf_attrs = get_zhuangbei_attrs_for_name(ren, '命中增幅')
    zb_zf_mm = sum_attrs(zb_zf_attrs)

    # 5. 计算结果
    result = (jn_mm + zb_mm + 100) * (1 + jn_zf_mm + zb_zf_mm)
    return int(result)

def pikan_result(ren):
    '''
    计算人物劈砍攻击力
    :param pk:
    :return:
    '''

    # 获取基础点数加成
    renattr = renwuattrs.objects.get(renwu=ren)
    jc = renattr.liliang * 5 + renattr.minjie * 3

    # 获取技能加成,增幅
    jn_jc = sum_attrs(get_jineng_attrs_for_name(ren, "劈砍攻击力"))
    jn_zf = sum_attrs(get_jineng_attrs_for_name(ren, '劈砍攻击力增幅'))

    # 获取装备加成,增幅
    zb_jc = sum_attrs(get_zhuangbei_attrs_for_name(ren, "劈砍攻击力"))
    zb_zf = sum_attrs(get_zhuangbei_attrs_for_name(ren, '劈砍攻击力增幅'))

    # 判断是否空手
    zf_type = get_wuqi_type(ren)

    # 如果不是空手
    if "空手" not in zf_type:
        # (基础属性劈砍+技能,装备增加的劈砍)*(1+装备技能劈砍增幅)
        return int((jc + jn_jc + zb_jc) * (1 + jn_zf + zb_zf))

    # 获取技能\装备空手增幅伤害
    jn_ks = sum_attrs(get_jineng_attrs_for_name(ren, "空手伤害增幅"))
    zb_ks = sum_attrs(get_zhuangbei_attrs_for_name(ren, '空手伤害增幅'))

    # 1. 不算空手增幅的劈砍攻击力
    sum_pk1 = (jc + jn_jc + zb_jc) * (1 + jn_zf + zb_zf)
    # 2. 计算空手增幅后的
    result = sum_pk1 + (jc + jn_jc + zb_jc) * (jn_ks + zb_ks)

    return round(result)


def chuanci_result(ren):
    '''
    计算人物穿刺攻击力
    :param pk:
    :return:
    '''

    # 获取基础点数加成
    renattr = renwuattrs.objects.get(renwu=ren)
    jc = renattr.liliang * 5 + renattr.minjie * 5

    # 获取技能加成,增幅
    jn_jc = sum_attrs(get_jineng_attrs_for_name(ren, "穿刺攻击力"))
    jn_zf = sum_attrs(get_jineng_attrs_for_name(ren, '穿刺攻击力增幅'))

    # 获取装备加成,增幅
    zb_jc = sum_attrs(get_zhuangbei_attrs_for_name(ren, "穿刺攻击力"))
    zb_zf = sum_attrs(get_zhuangbei_attrs_for_name(ren, '穿刺攻击力增幅'))

    # 判断是否空手
    zf_type = get_wuqi_type(ren)

    # 如果不是空手
    if "空手" not in zf_type:
        # (基础属性劈砍+技能,装备增加的穿刺)*(1+装备技能穿刺增幅)
        return int((jc + jn_jc + zb_jc) * (1 + jn_zf + zb_zf))

    # 获取技能\装备空手增幅伤害
    jn_ks = sum_attrs(get_jineng_attrs_for_name(ren, "空手伤害增幅"))
    zb_ks = sum_attrs(get_zhuangbei_attrs_for_name(ren, '空手伤害增幅'))

    # 1. 不算空手增幅的穿刺攻击力
    sum_pk1 = (jc + jn_jc + zb_jc) * (1 + jn_zf + zb_zf)
    # 2. 计算空手增幅后的
    result = sum_pk1 + (jc + jn_jc + zb_jc) * (jn_ks + zb_ks)

    return int(result)


def wushang_result(ren):
    '''
    计算武器伤害
    :param pk:
    :return:
    '''

    # 获取人物武器
    wuqi = renwu_zhuangbei.objects.filter(Q(renwu=ren) & Q(zhuangbei__leixing="wuqizuo")).first()

    # 如果没有穿戴武器
    if not wuqi:
        return "0"

    # 穿戴武器
    # 判断武器类型
    wq_type = get_wuqi_type(ren)

    # 获取武器伤害
    wq_min = min_attrs(get_zhuangbei_attrs_for_name(ren, "最低武器伤害"))
    wq_max = max_attrs(get_zhuangbei_attrs_for_name(ren, '最高武器伤害'))

    # 获取技能增幅
    jn_zf = sum_attrs(get_jineng_attrs_for_name(ren, wq_type))

    # 获取装备增幅
    zb_zf = sum_attrs(get_zhuangbei_attrs_for_name(ren, wq_type))

    # 计算最终结果
    min_result = wq_min * (1 + jn_zf + zb_zf)
    max_result = wq_max * (1 + jn_zf + zb_zf)

    # 返回数据
    return f"{round(min_result)}~{round(max_result)}"


def gongci_result(ren):
    # 获取攻次type
    gc_type = get_gongci_type(ren)
    # print(gc_type)

    # 获取技能通用攻次
    gc1 = sum_attrs(get_jineng_attrs_for_name(ren, "攻击次数"))

    # 获取技能专属攻次
    jn_gc = sum_attrs(get_jineng_attrs_for_name(ren, gc_type))

    # 获取装备通用攻次
    gc2 = sum_attrs(get_zhuangbei_attrs_for_name(ren, "攻击次数"))

    # 获取装备专属攻次
    zb_gc = sum_attrs(get_zhuangbei_attrs_for_name(ren, gc_type))

    result = gc1 + gc2 + jn_gc + zb_gc

    return int(result)


def get_wuqi_type(ren):
    '''
    获取人物装备的武器
    :param ren:
    :return: 武器类型
    '''

    # 遍历装备的类型,获取装备名称对应的值

    result = renwu_zhuangbei.objects.filter(Q(renwu=ren) & Q(zhuangbei__leixing="wuqizuo")).first()

    if not result:
        return "空手伤害增幅"

    zb_name = result.zhuangbei.name

    type_dict = {
        "法杖武器伤害增幅": ['杖'],
        "远程武器伤害增幅": ['弓', '弩'],
        "刀类武器伤害增幅": ['刀'],
        '长柄武器伤害增幅': ['长枪'],
        "剑类武器伤害增幅": ['剑'],
        '法器武器伤害增幅': ['法器'],
        "重型武器伤害增幅": ['锤'],
        "火枪武器伤害增幅": ['火枪', '炮']
    }
    for key, value in type_dict.items():
        for item in value:
            if item in zb_name:
                return key


def get_gongci_type(ren):
    '''
    获取人物装备的武器
    :param ren:
    :return: 武器类型
    '''

    # 遍历装备的类型,获取装备名称对应的值

    result = renwu_zhuangbei.objects.filter(Q(renwu=ren) & Q(zhuangbei__leixing="wuqizuo")).first()

    if not result:
        return "空手攻次"

    zb_name = result.zhuangbei.name

    type_dict = {
        "法杖武器伤害增幅": ['杖'],
        "远程武器攻击次数": ['弓', '弩'],
        "刀类武器攻击次数": ['刀'],
        '长柄武器攻击次数': ['长枪'],
        "剑类武器攻击次数": ['剑'],
        '法器武器攻击次数': ['法器'],
        "重型武器攻击次数": ['锤'],
        "火枪武器攻击次数": ['火枪', '炮']
    }
    for key, value in type_dict.items():
        for item in value:
            if item in zb_name:
                return key


def get_jineng_attrs_for_name(ren, name):
    '''
    通过属性名称,获取用户关联的属性列表
    :param ren: 用户
    :param name:属性名
    :return:属性列表
    '''

    # 1. 获取技能列表
    jns = [x.jineng for x in renwu_jieng.objects.filter(renwu=ren).all()]
    # print(jns)

    # 2. 获取属性值所属的id
    name_id = jineng_attrs.objects.get(name=name)
    # print(name_id)

    # 3. 获取这些技能包含 查询name的属性项
    attrs = jineng_key_value.objects.filter(Q(jineng__in=jns) & Q(attr_name=name_id)).all()

    # 调试输出
    # for attr in attrs:
    #     print(attr.jineng,attr.attr_name,attr.attr_value)
    return attrs


def get_zhuangbei_attrs_for_name(ren, name):
    '''
    通过属性名称,获取用户关联的属性列表
    :param ren: 用户
    :param name:属性名
    :return:属性列表
    '''

    # 1. 获取装备列表
    zbs = [x.zhuangbei for x in renwu_zhuangbei.objects.filter(renwu=ren).all()]
    # print(jns)

    # 2. 获取属性值所属的id
    name_id = jineng_attrs.objects.get(name=name)
    # print(name_id)

    # 3. 获取这些技能包含 查询name的属性项
    attrs = zhuangbei_key_value.objects.filter(Q(zhuangbei__in=zbs) & Q(attr_name=name_id)).all()

    # 调试输出
    # for attr in attrs:
    #     print(attr.jineng,attr.attr_name,attr.attr_value)
    return attrs

def get_chenghao_attr_for_name(ren,name):
    try:
        ch=ren.chenghao
        name_id = jineng_attrs.objects.get(name=name)
        result=chenghao_key_value.objects.filter(Q(chenghao=ch.pk) & Q(attr_name=name_id)).get()
    except Exception as e:
        print(e)
        return 0
    return result.attr_value

def sum_attrs(attrs):
    '''
    对技能所属的属性项计算求和
    :param attrs: 属性列表,例如所有包含增加智力的技能属性项
    :return: 计算结果
    '''
    num = 0
    for attr in attrs:
        num += attr.attr_value
    return num


def min_attrs(attrs):
    if not attrs:
        return 0
    list = [attr.attr_value for attr in attrs]
    return min(list)


def max_attrs(attrs):
    if not attrs:
        return 0
    list = [attr.attr_value for attr in attrs]
    return max(list)
